package com.wanggy.mystore.controller;

import com.wanggy.mystore.entity.District;
import com.wanggy.mystore.service.IDistrictService;
import com.wanggy.mystore.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 省市区信息获取控制层
 */

@RestController
@RequestMapping("districts")
public class DistrictController extends BaseController{
    @Autowired
    private IDistrictService districtService;

    /**
     * 请求路径和父路径相同时用@GetMapping("/","")表示
     * districts后边跟/或者什么也不跟都会进入这个方法
     */

    /**
     * 根据父代码获取下属区域信息
     * @param parent 父代码
     * @return 下属区域信息
     */
    @GetMapping({"/",""})
    public JsonResult<List<District>> getByParent(String parent){
        List<District> list = districtService.getByParent(parent);

        return new JsonResult<>(OK,list);
    }
}

